package com.jjb.www.ui.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.view.View;

import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.hjq.base.BaseAdapter;
import com.hjq.http.EasyHttp;
import com.hjq.http.listener.HttpCallback;
import com.hjq.shape.view.ShapeImageView;
import com.hjq.shape.view.ShapeTextView;
import com.hjq.widget.layout.WrapRecyclerView;
import com.jjb.www.R;
import com.jjb.www.app.AppActivity;
import com.jjb.www.http.api.AgencyListApi;
import com.jjb.www.http.api.RefreshTokenApi;
import com.jjb.www.http.api.UserChangeListApi;
import com.jjb.www.http.glide.GlideApp;
import com.jjb.www.http.model.HttpData;
import com.jjb.www.http.model.HttpList;
import com.jjb.www.other.AppConfig;
import com.jjb.www.ui.adapter.VipAdapter;
/**
 * Author: crg
 * time:   2021/10/20 11:10
 * des:    开通会员
 */
public class VipActivity extends AppActivity implements BaseAdapter.OnItemClickListener {
    private ShapeImageView mImgHead;
    private ShapeTextView mTvName;
    private ShapeTextView mTvPhone;
    private ShapeTextView mTvRemake;
    private ShapeTextView mTvMemberTime;
    private ShapeTextView mTvMemberName;
    private ShapeTextView mTvTitle1;
    private ShapeTextView mTvTitle2;
    private WrapRecyclerView mRvList;
    private VipAdapter adapter;




    @Override
    protected int getLayoutId() {
        return R.layout.activity_vip;
    }

    @Override
    protected void initView() {
        mImgHead = findViewById(R.id.img_head);
        mTvName = findViewById(R.id.tv_name);
        mTvPhone = findViewById(R.id.tv_phone);
        mTvRemake = findViewById(R.id.tv_remake);
        mTvMemberTime = findViewById(R.id.tv_member_time);
        mTvMemberName = findViewById(R.id.tv_member_name);
        mTvTitle1 = findViewById(R.id.tv_title1);
        mTvTitle2 = findViewById(R.id.tv_title2);
        mRvList = findViewById(R.id.rv_list);
        mRvList.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new VipAdapter(getContext());
        adapter.setOnItemClickListener(this);
        mRvList.setAdapter(adapter);
    }

    @Override
    protected void initData() {
        getRefreshToken();
        getVip();

    }

    private void getVip() {
        EasyHttp.get(this)
                .api(new UserChangeListApi())
                .request(new HttpCallback<HttpData<UserChangeListApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<UserChangeListApi.Bean> data) {
                        mTvRemake.setText(data.getData().getContent().getRemake());
                        mTvMemberName.setText(data.getData().getMember_name());
                        mTvTitle1.setText(data.getData().getContent().getTitle1());
                        mTvTitle2.setText(data.getData().getContent().getTitle2());
                        if (data.getData().getIs_member()!=0){
                            mTvMemberTime.setText(data.getData().getMember_end_time());
                        }
                        adapter.setData(data.getData().getList());
                    }
                });
    }

    private void getRefreshToken() {
        EasyHttp.post(this)
                .api(new RefreshTokenApi()
                        .setUser_id(AppConfig.getInstance().getUserBean().getUser().getId()+""))
                .request(new HttpCallback<HttpData<RefreshTokenApi.Bean>>(this) {

                    @Override
                    public void onSucceed(HttpData<RefreshTokenApi.Bean> data) {
                        GlideApp.with(getActivity())
                                .load(data.getData().getUser().getImg())
                                .transform(new MultiTransformation<>(new CenterCrop(), new CircleCrop()))
                                .into(mImgHead);
                        mTvName.setText(data.getData().getUser().getNickname());
                        mTvPhone.setText(data.getData().getUser().getMobile());
                    }
                });
    }

    @Override
    public void onItemClick(RecyclerView recyclerView, View itemView, int position) {
        toast("跳转支付");
    }
}